package com.huangd.platform.modules.sys.interceptor;

import com.huangd.platform.modules.sys.entity.TblUserEntity;
import org.apache.shiro.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 登录拦截器。游戏导航操作时、检查服务器选择
 * 
 * @author wing
 * 
 */

@Component
public class AuthInterceptor implements HandlerInterceptor {


	private static final Logger logger = LoggerFactory.getLogger(AuthInterceptor.class);

	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception e) throws Exception {
	}

	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView v) throws Exception {
		
	}

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

		String uri = request.getServletPath();
		HttpSession session = request.getSession();
		TblUserEntity userEntity = (TblUserEntity) SecurityUtils.getSubject().getPrincipal();

		if (userEntity != null) {
			request.getParameterMap();

			logger.info("后台日志,USER:{},name:{},ip:{},uri:{},param:{}", userEntity.getId(), userEntity.getName(), request.getRemoteAddr(), uri, request.getParameterMap());
		}

		return true;
	}
}